package com.ytjj.qmyx.admin.service.impl;

import com.ytjj.qmyx.admin.model.request.HotSearchRequest;
import com.ytjj.qmyx.admin.service.HotSearchService;
import com.ytjj.qmyx.mall.mapper.HotSearchMapper;
import com.ytjj.qmyx.mall.model.HotSearch;
import com.ytjj.qmyx.mall.model.HotSearchExample;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Slf4j
@Service
public class HotSearchServiceImpl implements HotSearchService {
    @Resource
    private HotSearchMapper hotSearchMapper;

    @Override
    public List<HotSearch> list() {
        HotSearchExample hotSearchExample = new HotSearchExample();
        hotSearchExample.setOrderByClause("create_time DESC");
        return hotSearchMapper.selectByExample(hotSearchExample);
    }

    @Override
    public int add(HotSearchRequest hotSearchRequest) {
        hotSearchRequest.setCreateTime(new Date());
        return hotSearchMapper.insert(hotSearchRequest);
    }

    @Override
    public int updateHotSearch(HotSearchRequest hotSearchRequest) {
        hotSearchRequest.setUpdateTime(new Date());
        return hotSearchMapper.updateByPrimaryKeySelective(hotSearchRequest);
    }

    @Override
    public int deleteById(HotSearchRequest hotSearchRequest) {
        return hotSearchMapper.deleteByPrimaryKey(hotSearchRequest.getId());
    }
}
